import {App, render} from 'vue'

export function menu(app: App) {

    app.directive('contextMenu', {
        mounted(el, binding) {
            el.addEventListener('contextmenu', (event: Event) => {
                event.preventDefault()

                if(typeof binding.value === "function"){
                    binding.value(event)
                }
            })

            document.addEventListener("click", (event: any)=>{
                const menu =  document.getElementById("right_click_menu")
                if (menu) {
                    render( null, document.body)
                }
            })
        },
        unmounted(el) {
            el.removeEventListener('contextMenu', ()=> {})
        }
    })
}
